package net.xdclass.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import net.xdclass.mapper.BannerMapper;
import net.xdclass.model.BannerDO;
import net.xdclass.service.BannerService;
import net.xdclass.vo.BannerVo;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.stream.Collectors;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author 孙浩
 * @since 2022-04-24
 */
@Service
public class BannerServiceImpl implements BannerService {

  @Autowired
  private BannerMapper bannerMapper;

  @Override
  public List<BannerVo> list() {
    return bannerMapper.selectList(new QueryWrapper<BannerDO>()
          .orderByDesc("weight"))
          .stream()
          .map(this::transformation)
        .collect(Collectors.toList());
  }

  private BannerVo transformation(BannerDO bannerDO){
    BannerVo bannerVo = new BannerVo();
    BeanUtils.copyProperties(bannerDO,bannerVo);
    return bannerVo;
  }

}
